<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
	
	public function login(){
		if(IS_POST){
			//php获取ip的算法
			if ($HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"])
			{
				$ip = $HTTP_SERVER_VARS["HTTP_X_FORWARDED_FOR"];
			}
			elseif ($HTTP_SERVER_VARS["HTTP_CLIENT_IP"])
			{
				$ip = $HTTP_SERVER_VARS["HTTP_CLIENT_IP"];
			}
			elseif ($HTTP_SERVER_VARS["REMOTE_ADDR"])
			{
				$ip = $HTTP_SERVER_VARS["REMOTE_ADDR"];
			}
			elseif (getenv("HTTP_X_FORWARDED_FOR"))
			{
				$ip = getenv("HTTP_X_FORWARDED_FOR");
			}
			elseif (getenv("HTTP_CLIENT_IP"))
			{
				$ip = getenv("HTTP_CLIENT_IP");
			}
			elseif (getenv("REMOTE_ADDR"))
			{
				$ip = getenv("REMOTE_ADDR");
			}
			else
			{
				$ip = "Unknown";
			}
			$returnLoginInfo = D("Login")->auth();
			if($returnLoginInfo['status']!=0){
				$this->error($returnLoginInfo['info']);
			}else{ 
				$data['zuiip']=$ip;
				$data['zuitime'] = date('Y-m-d H:i:s',time());
	            M('admin')->where(array('uid'=>$_SESSION['my_info']['uid']))->save($data);
				$this->redirect("Index/index");
			}
		}else{
			$this->display();
		}
	}
    
    
    public function loginout(){
    	unset($_SESSION['my_info']);
		S('bcate',null);
		S('scate',null);
		S('sacate',null);
		
    	$this->redirect('login/login');
    }
}